Skip to content

Use MPI types that match REAL and INTEGER in wrf_dm_maxval and wrf_dm_minval - #2450

Open
mirfjc wants to merge 1 commit into
wrf-model:release-v4.8.2from
mirfjc:dm_maxval_minval_mpi_types
Open

mirfjc wants to merge 1 commit into
wrf-model:release-v4.8.2from
mirfjc:dm_maxval_minval_mpi_types

Conversation

@mirfjc

@mirfjc mirfjc commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

TYPE: bug fix

KEYWORDS: RSL_LITE, MPI, MAXLOC, MINLOC, double precision, -r8

SOURCE: Mark I. Richardson (Aeolis Research)

DESCRIPTION OF CHANGES:
Problem:
wrf_dm_maxval_real and wrf_dm_minval_real (external/RSL_LITE/module_dm.F) reduce their (value, rank) pair with MPI_2REAL whatever the size of REAL. With -r8 the pair is two 8-byte reals, so MAXLOC and MINLOC compare the wrong bits and return one rank's value, not the domain maximum or minimum. All four float variants also broadcast the INTEGER index pair as MPI_REAL or MPI_DOUBLE_PRECISION. Details in #2449.

Solution:
A new internal function getreal2mpitype returns MPI_2REAL or MPI_2DOUBLE_PRECISION by RWORDSIZE, as getrealmpitype does for MPI_REAL and MPI_DOUBLE_PRECISION, and the two real variants use it. All four routines broadcast the index pair as MPI_INTEGER. In a default (4-byte REAL) build the MPI types are the same as before.

ISSUE:
Fixes #2449

LIST OF MODIFIED FILES:
M external/RSL_LITE/module_dm.F

TESTS CONDUCTED:

  1. Yes. A small program doing the same reduction, built with mpif90 -fdefault-real-8 -fdefault-double-8 and run on 4 ranks (rank r holds 1.5 + 10 r): with MPI_2REAL and MPI_REAL it returns 1.50 and an unset rank; with the types used here it returns 31.50, rank 3, and rank 3's index pair. WRF built on release-v4.8.1 (81303ee) with configure option 35, Homebrew gfortran/gcc 16.2.0 at -O2, macOS on Apple Silicon.
  2. The regression (Jenkins) tests: not yet run.

RELEASE NOTE: In builds with 8-byte REAL (configure -r8) and MPI, the domain maximum and minimum from wrf_dm_maxval and wrf_dm_minval are now correct. They set the map-factor maxima that the adaptive time step uses for the number of acoustic steps, and several diagnostics.

…_minval

wrf_dm_maxval_real and wrf_dm_minval_real reduced their (value, rank) pair
with MPI_2REAL whatever the size of REAL, so with -r8 the MAXLOC and MINLOC
compared the wrong bits and returned one rank's value instead of the domain
maximum or minimum. The pair type now follows RWORDSIZE, as getrealmpitype
does for single values. The index pair is INTEGER, so all four routines now
broadcast it as MPI_INTEGER: the real variants sent it as MPI_REAL (right
only because both are 4 bytes) and the doubleprecision variants as
MPI_DOUBLE_PRECISION (16 bytes from an 8-byte buffer). A default build does
the same as before.
@mirfjc
mirfjc requested a review from a team as a code owner November 7, 2026 07:29
@weiwangncar

Copy link
Copy Markdown
Collaborator

The regression test results:

Test Type              | Expected  | Received |  Failed
= = = = = = = = = = = = = = = = = = = = = = = =  = = = =
Number of Tests        : 23           24
Number of Builds       : 60           57
Number of Simulations  : 158           150        0
Number of Comparisons  : 95           86        0

Failed Simulations are: 
None
Which comparisons are not bit-for-bit: 
None

dudhia
dudhia previously approved these changes Dec 4, 2026

@dudhia dudhia left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A fix for double precision use

@dudhia
dudhia changed the base branch from release-v4.8.1 to release-v4.8.2 December 4, 2026 16:17
@dudhia
dudhia dismissed their stale review December 4, 2026 16:17

The base branch was changed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants